/**************************************************************************************************
* Title: SumMeshManager.h
* Author: Gael Huber
* Description: Specific resource group for handling mesh objects. 
**************************************************************************************************/
#ifndef __SUMMESHMANAGER_H__
#define __SUMMESHMANAGER_H__

#include "SumResourceGroup.h"
#include "SumMesh.h"
#include "SumSingleton.h"

using namespace std;

class MeshManager : public ResourceGroup, public Singleton<MeshManager> {
public:
	// Default constructor
	MeshManager(void);

	// Destructor
	~MeshManager(void);

	// Get singleton
	inline static MeshManager& getSingleton(void)
	{
		assert(singleton);
		return *singleton;
	}
	// Get singleton pointer
	inline static MeshManager* getSingletonPtr(void)
	{
		return singleton;
	}

	// Initialize resource group. Resource groups are initialized by reading in filenames in given 
	// directories and associating names with resources. The actual resources are not loaded until
	// they are needed.
	void initializeResourceGroup(const String& name, const List<String>& directories);

	// Unload all resources present in the resource group
	void unloadResourceGroup(void);

	// Unload a specific resource in the group
	void unloadResource(const String& name);

	// Retrieve a mesh from the manager
	Mesh* retrieveMesh(const String& name);

private:
	// Internal function used to retrieve/create a mesh object
	Mesh* _retrieveOrCreateMesh(const String& name);

	// Load a mesh from file
	Mesh* _loadMesh(const String& name);

	// Hashmap of all mesh resources
	HashMap<String, Mesh*> _resources;

	// Hashmap of all resource paths
	HashMap<String, String> _resourcePaths;
};

#endif